<template>
	<view class="index">
		<user :query="userQuery" @changeCoach="changeCoach" @changeManager="changeManager" @changeStock="changeStock" :tokenShow="tokenShow"
			:rewardShow="userQuery.card_info.is_bright?true:false" v-if="type == 'user'"></user>
		<coach v-if="type == 'coach'" @changMy="changMy"></coach>
		<manager v-if="type == 'manager'" @MnchangeMy="changMy"></manager>
		<stock v-if="type == 'stock'" @MnchangeMy="changMy"></stock>
		<!-- <skockNew v-if="type == 'stock'" @MnchangeMy="changMy"></skockNew> -->
		
	</view>
</template>

<script>
	import user from './user.vue';
	import coach from './coach.vue'
	import manager from './manager.vue'
	import stock from './stock.vue'
	// import skockNew from './skockOne.vue'
	import {
		userMain
	} from '@/api/user.js'
	export default {
		components: {
			user,
			coach,
			manager,
			stock,
			// skockNew
		},
		data() {
			return {
				type: 'user',
				// 用户数据
				userQuery: {},
				Field: [],
				managerQuery: {},
				tokenShow:false,
				
			}
		},
		onShow() {
			this.getInfo()
			this.$CHECKTOKEN().then(isValid => {
			    if (isValid) {
			        console.log('Token is valid', isValid);
					this.tokenShow = true
			    } else {
					this.tokenShow = false
			        console.log('Token is invalid or not found', isValid);
			    }
			}).catch(error => {
				this.tokenShow = false
			    console.error('Error checking token:', error);
			});
			let that = this
			uni.$on('loginOut', function(data) {
				that.userQuery = {}
			})
		},
		methods: {
			getInfo() {
				userMain().then(({
					data: res
				}) => {
					console.log('res邀请', res);
					if (res.code == 1) {
						this.userQuery = res.data
					} else {

					}
				})
			},
			changeCoach(data) {
				if (!data) {
					uni.navigateTo({
						url: '/pageB/user/become_coach/index'
					})
				} else {
					// this.type = "coach"
					wx.navigateToMiniProgram({
						appId: 'wxc02a615d7b194643', // 必填，要跳转的目标小程序的appId
						path: 'pages/index/index', // 打开的页面路径，如果留空则打开首页
						extraData: { // 需要传递给目标小程序的数据，目标小程序可在 App.onLaunch 或者 App.onShow 中获取到这部分数据
						},
						envVersion: '', // 要打开的像是开发版（develop）、体验版（trial）还是正式版（release），若不填默认是正式版
						success(res) {
							// 调用成功的回调函数
							console.log('打开成功', res);
						},
						fail(err) {
							// 调用失败的回调函数
							console.log('打开失败', err);
						}
					});
				}
			},
			changMy() {
				this.type = "user"
			},
			changeManager() {
				this.type = 'manager'
			},
			changeStock(){
				this.type = 'stock'
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #e9e9e9;
	}
</style>